//
//  MBProgressHUD+MJ.m
//
//  Created by mj on 13-4-18.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "MBProgressHUD+MJ.h"

@implementation MBProgressHUD (MJ)
#pragma mark 显示信息
+ (void)mj_show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    //显示之前先把原来的取消掉
    [self mj_hideHUDForView:view];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = [UIColor colorWithRed:41/255.0 green:41/255.0 blue:41/255.0 alpha:0.7];
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    hud.contentColor = [UIColor whiteColor];
//    hud.label.textColor = [UIColor whiteColor];
    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // 1秒之后再消失
    [hud hideAnimated:YES afterDelay:1];
}
#pragma mark 显示信息
+ (void)mj_show:(NSString *)text icon:(NSString *)icon view:(UIView *)view isHidden:(BOOL)hidden
{
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    //显示之前先把原来的取消掉
    [self mj_hideHUDForView:view];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = [UIColor colorWithRed:41/255.0 green:41/255.0 blue:41/255.0 alpha:0.7];
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    hud.contentColor = [UIColor whiteColor];
    //    hud.label.textColor = [UIColor whiteColor];
    // 设置图片
    if (!hidden) {
        hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    }
    
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // 1秒之后再消失
    [hud hideAnimated:YES afterDelay:1.5];
}
#pragma mark 显示错误信息
+ (void)mj_showError:(NSString *)error toView:(UIView *)view{
    [self mj_show:error icon:@"error.png" view:view];
}

+ (void)mj_showSuccess:(NSString *)success toView:(UIView *)view
{
    [self mj_show:success icon:@"success.png" view:view];
}

#pragma mark 显示一些信息
+ (MBProgressHUD *)mj_showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = [UIColor colorWithRed:41/255.0 green:41/255.0 blue:41/255.0 alpha:0.7];
    hud.contentColor = [UIColor whiteColor];
    hud.label.text = message;
    hud.label.numberOfLines = 0;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    return hud;
}

+ (void)mj_showSuccess:(NSString *)success
{
    [self mj_showSuccess:success toView:nil];
}

+ (void)mj_showError:(NSString *)error
{
    [self mj_showError:error toView:nil];
}

+ (MBProgressHUD *)mj_showMessage:(NSString *)message
{
    return [self mj_showMessage:message toView:nil];
}

+ (MBProgressHUD *)mj_showLoading{
    return [MBProgressHUD mj_showLoadingInView:nil];
}

+ (MBProgressHUD *)mj_showLoadingInView:(UIView *)view{
    if (!view) {
        view = [[UIApplication sharedApplication].windows lastObject];
    }
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = [UIColor colorWithRed:41/255.0 green:41/255.0 blue:41/255.0 alpha:0.7];
   return hud;
}

+ (MBProgressHUD *)mj_showWithOnlyMessage:(NSString *)message{
    [self mj_hideHUD];
    MBProgressHUD *hud = [MBProgressHUD mj_showMessage:message];
    hud.mode = MBProgressHUDModeText;
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = [UIColor colorWithRed:41/255.0 green:41/255.0 blue:41/255.0 alpha:0.7];
    hud.contentColor = [UIColor whiteColor];
    [hud hideAnimated:YES afterDelay:1];
    return hud;
}

+ (void)mj_hideHUDForView:(UIView *)view
{
    if (!view) {
        view = [[UIApplication sharedApplication].windows lastObject];
    }
    [MBProgressHUD hideAllHUDsForView:view animated:YES];
}

+ (void)mj_hideHUD
{
    [self mj_hideHUDForView:nil];
}
+ (void)zr_showError:(NSString *)error {
    [self mj_show:error icon:nil view:nil isHidden:YES];
}
@end
